[t:/]$ 지식_

GTK+ 없이 pango 쓰기.

2009/01/22

pango - cairo 는 gtk+를 위해서 만들어졌지만 사실은 범용 라이브러리이다.

...라고는 하나 단독으로 사용하는 사람은 거의 없는 것 같다. -_-;

배경지식

cairo : 2D 그래픽 라이브러리다.
pango : 다양한 기능의 폰트 렌더러다.

사전에 필요한 라이브러리들이 모두 빌드되어 있어야 한다. 대충 생각나는 것만 해도..

glib, pixmap, fontconfig, freetype2, libpng, libxml2, iconv ... 어휴 많다..

cairo-pango로 할 수 있는 것

cairo를 백엔드 기능으로 적용하여 pango를 빌드해서 쓰면 여러가지 작업을 할 수 있다. 예를 들어 글자를 원형으로 굴려쓰기라든가, 문자열 내에 태그등을 넣어 데코레이션을 줄 수 있다. 또한 정해진 사각 영역안에 문단 흐르기등을 자동화 할 수 있다.

목표

느린 gtk+를 걷어내고 directFB에서 다이렉트로 pango 기능을 써보자.

문제점

아직 directFB surface 버퍼 안에 넣는 작업을 실패했다. 여기서는 tmpfs 파일시스템으로 /tmp를 잡고 여기에 png 파일을 쓴 후 다시 렌더링 하는 방식. 지극히 비효율적인 방식을 통해서만 시도해보았다.

. . .

코드를 보자.

      cairo_t *cr;
      cairo_surface_t *surface;    
      unsigned int w, h;

      surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 300, 300);
      cr = cairo_create (surface);

      cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
      cairo_paint (cr);
      draw_text (cr, &w, &h);
      cairo_destroy (cr);
      status = cairo_surface_write_to_png (surface, "/tmp/temp1.png");
      cairo_surface_destroy (surface);      
      
      

static void draw_text (cairo_t *cr, unsigned int *w, unsigned int *h)
{
    PangoLayout *layout;
    PangoFontDescription *desc;
    int i;
    char *rrr = "Hello 안<span foreground=\"blue\">녕</span>하세요? 반갑습니다. 고현정 만세~ 감기야 가라~";
    
    
    /* Create a PangoLayout, set the font and text */
    layout = pango_cairo_create_layout (cr);
    pango_layout_set_width (layout, 300 * PANGO_SCALE);
    pango_layout_set_height (layout, 300 * PANGO_SCALE);
    
    pango_layout_set_markup (layout, rrr, -1);
    
    desc = pango_font_description_from_string (FONT);
    pango_layout_set_font_description (layout, desc);
    pango_font_description_free (desc);
    
    cairo_save (cr);
    pango_cairo_update_layout (cr, layout);

   
    pango_cairo_show_layout (cr, layout);

    cairo_restore (cr);  

      /* free the layout object */
      g_object_unref (layout);
}

대충 때려 빌드.

arm-linux-gcc -DHAVE_CONFIG_H -I. -I.. -I.. -DG_DISABLE_CAST_CHECKS -pthread -I/dfb/include/glib-2.0 -I/dfb/lib/glib-2.0/include    -D_REENTRANT -I/dfb/include/cairo -I/dfb/include/pixman-1 -I/dfb/include/freetype2 -I/dfb/include -I/dfb/include/directfb -I/dfb/include/libpng12   -I/dfb/include/freetype2 -I/dfb/include   -I/dfb/include       -fno-delete-null-pointer-checks -I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/pixman-1  -lcairo -I/dfb/include/cairo -I/dfb/include/pixman-1 -I/dfb/include/freetype2 -I/dfb/include -I/dfb/include/directfb -I/dfb/include/libpng12 -D_REENTRANT -I/dfb/include/directfb  -L/dfb/lib -ldirectfb -lfusion -ldirect -lpthread -I/dfb/include/pango-1.0 -I/dfb/include/glib-2.0 -I/dfb/lib/glib-2.0/include  -L/dfb/lib -lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -lfontconfig -lglib-2.0 -lpixman-1 -lfreetype -lpangocairo-1.0 -liconv -lpng -lxml2 -lpangoft2-1.0 -o dfbg dfbg.c




공유하기













[t:/] is not "technology - root". dawnsea, rss